package com.digua.base

import android.os.Bundle
import android.widget.TextView
import androidx.core.view.setPadding
import com.blankj.utilcode.util.ClipboardUtils
import com.blankj.utilcode.util.SizeUtils
import com.blankj.utilcode.util.ToastUtils
import com.digua.base.databinding.ActivityMainBinding
import com.digua.base.ui.base.BaseActivity

class MainActivity : BaseActivity<ActivityMainBinding>() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initUI()
    }

    private fun initUI() {
        ui?.apply {
            var i: Int = 1
            contents.addView(getTextView("${i++}、Android版本为:26+"))
            contents.addView(getTextView("""
                ${i++}、在主项目的Setting.gradle中加入如下代码:
                ${"\t\t\t"}include(":base")
                ${"\t\t\t"}//project(":base").projectDir=File("base项目目录")
                ${"\t\t\t"}project(":base").projectDir=File("D:/project/digua/AndroidKotlinBaseProject/code/AndroidKotlinBaseProject/base")
            """.trimIndent(), """
                include(":base")
                //project(":base").projectDir=File("base项目目录")
                project(":base").projectDir=File("D:/project/digua/AndroidKotlinBaseProject/code/AndroidKotlinBaseProject/base")
            """.trimIndent()))
            contents.addView(getTextView("${i++}、引用项目可复制本项目MyApp使用,BaseActivity也同样"))
            contents.addView(getTextView("""
                ${i++}、在app项目中的build.gradle文件中加入如下代码:
                ${"\t\t\t"}android {
                ${"\t\t\t"}    viewBinding {
                ${"\t\t\t"}        enable = true
                ${"\t\t\t"}    }
                ${"\t\t\t"}}
            """.trimIndent(), """
                viewBinding {
                    enable = true
                }
            """.trimIndent()))
            contents.addView(getTextView("${i++}、注意项目的主题请使用Theme.Digua.Base或继承Theme.Digua.Base"))
            contents.addView(getTextView("${i++}、更多可参考:https://blog.csdn.net/saintcs/article/details/78567612", "https://blog.csdn.net/saintcs/article/details/78567612"))
        }
    }

    private fun getTextView(content: String, copyContent: String? = null): TextView {
        val view = TextView(this)
        view.setPadding(SizeUtils.dp2px(5F))
        view.text = content
        copyContent?.let { txt ->
            view.setOnClickListener {
                ClipboardUtils.copyText(txt)
                ToastUtils.showShort("复制成功")
            }
        }
        return view
    }
}
